# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH $ORIGIN)

set(JPEG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libjpeg)
set(PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libpng)
set(TIFF_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libtiff)
set(JPEG_TURBO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libjpeg-turbo)
set(WEBP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../libwebp)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-address-of-packed-member")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")

file(GLOB hdr "*.h")
file(GLOB src "*.c")

add_library (leptonica SHARED ${src} ${hdr})

#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../libjpeg ${CMAKE_CURRENT_BINARY_DIR}/libjpeg)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../libpng ${CMAKE_CURRENT_BINARY_DIR}/libpng)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../libjpeg-turbo ${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../libtiff ${CMAKE_CURRENT_BINARY_DIR}/libtiff)
#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../libwebp ${CMAKE_CURRENT_BINARY_DIR}/libwebp)


#target_include_directories  (leptonica PUBLIC ${JPEG_INCLUDE_DIR})
#target_link_libraries       (leptonica PRIVATE jpeg)

target_include_directories  (leptonica PUBLIC ${PNG_INCLUDE_DIR})
target_link_libraries       (leptonica PRIVATE png)

target_include_directories  (leptonica PUBLIC ${TIFF_INCLUDE_DIR})
target_link_libraries       (leptonica PRIVATE tiff)

target_include_directories  (leptonica PUBLIC ${JPEG_TURBO_INCLUDE_DIR})
target_link_libraries       (leptonica PRIVATE jpeg-turbo)

#target_include_directories  (leptonica PUBLIC ${WEBP_INCLUDE_DIR})
#target_link_libraries       (leptonica PRIVATE webp)